function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
% function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
%
% File created by Dynare Preprocessor from .mod file
%
% Inputs:
%   T             [#temp variables by 1]     double   vector of temporary terms to be filled by function
%   y             [#dynamic variables by 1]  double   vector of endogenous variables in the order stored
%                                                     in M_.lead_lag_incidence; see the Manual
%   x             [nperiods by M_.exo_nbr]   double   matrix of exogenous variables (in declaration order)
%                                                     for all simulation periods
%   steady_state  [M_.endo_nbr by 1]         double   vector of steady state values
%   params        [M_.param_nbr by 1]        double   vector of parameter values in declaration order
%   it_           scalar                     double   time period for exogenous variables for which
%                                                     to evaluate the model
%   T_flag        boolean                    boolean  flag saying whether or not to calculate temporary terms
%
% Output:
%   residual
%

if T_flag
    T = bbeffectivedemandmatchirf_order4.dynamic_resid_tt(T, y, x, params, steady_state, it_);
end
residual = zeros(27, 1);
lhs = y(35)+params(15);
rhs = T(1)*T(2);
residual(1) = lhs - rhs;
lhs = y(11)+params(14)*y(19)/y(27);
rhs = y(21)*y(34)+y(12)+y(4)*params(14);
residual(2) = lhs - rhs;
lhs = y(34);
rhs = y(11)*T(3)/(1-y(21));
residual(3) = lhs - rhs;
lhs = y(32);
rhs = T(8)^T(9);
residual(4) = lhs - rhs;
lhs = y(17);
rhs = y(46)^(1-params(9));
residual(5) = lhs - rhs;
lhs = y(21)*y(34);
rhs = (y(35)+params(15))*(1-params(1))/y(20);
residual(6) = lhs - rhs;
lhs = y(4)*y(30)*y(28);
rhs = (y(35)+params(15))*params(1)/y(20);
residual(7) = lhs - rhs;
lhs = y(4)*y(30)*y(25)*y(14);
rhs = (y(35)+params(15))*params(1)/y(20);
residual(8) = lhs - rhs;
lhs = y(19);
rhs = y(18)+y(4)*T(11);
residual(9) = lhs - rhs;
lhs = y(13);
rhs = params(3)+params(4)*(y(30)-1)+params(5)/2*(y(30)-1)^2;
residual(10) = lhs - rhs;
lhs = y(14);
rhs = params(4)+(y(30)-1)*params(5);
residual(11) = lhs - rhs;
lhs = y(29);
rhs = T(19)*T(20)*T(23);
residual(12) = lhs - rhs;
lhs = 1;
rhs = y(27)*y(44);
residual(13) = lhs - rhs;
lhs = 1;
rhs = y(44)*y(26)*T(24);
residual(14) = lhs - rhs;
lhs = 1;
rhs = y(44)*(y(37)+y(40))/y(22);
residual(15) = lhs - rhs;
lhs = log(y(26));
rhs = (1-params(16))*(log(params(41))+params(17)*log(T(25))+params(18)*log(T(26)))+params(16)*log(y(6));
residual(16) = lhs - rhs;
lhs = y(12);
rhs = y(35)-y(21)*y(34)-y(18)-y(35)*T(27)-params(14)*(y(4)-y(19)/y(27));
residual(17) = lhs - rhs;
lhs = 1;
rhs = T(30)/y(25);
residual(18) = lhs - rhs;
lhs = 1/y(25);
rhs = 1-params(8)*(y(18)/y(4)-params(3));
residual(19) = lhs - rhs;
lhs = T(25)*params(7)*(T(25)-1);
rhs = 1-params(13)+params(13)/y(20)+T(31)*T(33);
residual(20) = lhs - rhs;
lhs = y(24);
rhs = y(35)*(y(20)-1)-params(15);
residual(21) = lhs - rhs;
lhs = y(15);
rhs = (y(37)+y(40))/y(22);
residual(22) = lhs - rhs;
lhs = y(16);
rhs = T(34)/T(35);
residual(23) = lhs - rhs;
lhs = y(31);
rhs = y(16)-y(15)^2;
residual(24) = lhs - rhs;
lhs = y(10);
rhs = (1-params(19))*params(25)+y(1)*params(19)+y(7)*x(it_, 1);
residual(25) = lhs - rhs;
lhs = y(33);
rhs = y(7)*params(20)+(1-params(20))*params(48)+params(21)*x(it_, 2);
residual(26) = lhs - rhs;
lhs = y(36);
rhs = (1-params(22))*params(52)+params(22)*y(9)+params(49)*x(it_, 3);
residual(27) = lhs - rhs;

end
